package cn.virens.database.serviceimpl.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.virens.database.common.BaseServiceImpl;
import cn.virens.database.enums.log.Level;
import cn.virens.database.enums.log.Type;
import cn.virens.database.mysql.mapper.sys.SysLogMapper;
import cn.virens.database.mysql.model.sys.SysLog;
import cn.virens.database.service.sys.SysLogService;

@Service
public class SysLogServiceImpl extends BaseServiceImpl<SysLog, SysLogMapper> implements SysLogService {
	@Autowired
	public SysLogServiceImpl(SysLogMapper mBaseMapper) {
		super(mBaseMapper);
	}

	@Override
	public int log(String account, Type type, Level level, String host, String content) {
		SysLog log = new SysLog();
		log.setUser(account);
		log.setType(type);
		log.setLevel(level);
		log.setHost(host);
		log.setContent(content);
		try {
			return insert(log);
		} catch (Exception e) {
			return 0;
		}
	}

	@Override
	public int log(String account, Type type, String host, String content) {
		return log(account, type, Level.DEBUG, host, content);
	}

	@Override
	public int log(String account, String host, String content) {
		return log(account, Type.USER, Level.DEBUG, host, content);
	}

	@Override
	public int log(String account, String content) {
		return log(account, Type.USER, Level.DEBUG, "0.0.0.0", content);
	}

	@Override
	@Transactional
	public int clear() {
		return mBaseMapper.clear();
	}

	@Override
	protected Class<SysLog> getGenericSuperclass() {
		return SysLog.class;
	}

}
